<!DOCTYPE html>
<html lang="en">  
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
	<title>我的记录</title>
</head>
<link rel="stylesheet" href="__CSS__/record.min.css">
<body>
	<div id="app" v-cloak v-if="userInfo.id!=undefined">
		<div class="chooseType">
			<span :class="{active:type==1}" @click="type=1">我发出的</span>
			<span :class="{active:type==2}" @click="type=2">我收到的</span>
		</div>
		<div class="Pic">
			<img :src="userInfo.headurl" alt="">
		</div>
		<div class="Name">
			<span>{{userInfo.nickname}}</span> <span v-if="type==1">共发出</span><span v-if="type==2">共收到</span>
		</div>
		<div class="bigMoney">
			<span v-if="type==1">{{sendPrice|toFixed(sendPrice)}}<span>元</span></span>
			<span v-if="type==2">{{getPrice|toFixed(getPrice)}}<span>元</span></span>
		</div>
		<div class="totalNum">
			<span v-if="type==1">{{sendNum}}<span>个</span></span>
			<span v-if="type==2">{{getNum}}<span>个</span></span>
		</div>
		<div v-if="type==1">
			<div class="List" v-for="vo in mygive" @click="goto(vo.id)">
				<p>
					<span>{{vo.commond}}</span>
					<span><span class="price">{{vo.money}}</span>元</span>
				</p>
				<p>
					<span>{{vo.add_time | time(vo.add_time)}}</span>
					<span>{{vo.number - vo.remain_number}}/{{vo.number}}</span>
				</p>
			</div>
		</div>
		<div v-if="type==2">
			<div class="List" v-for="vo in receive" @click="goto(vo.red_id)" >
				<p>
					<span>{{vo.commond}}</span>
					<span><span class="price">{{vo.money}}</span>元</span>
				</p>
				<p>
					<span>{{vo.add_time | time(vo.add_time)}}</span>
				</p>
			</div>
		</div>

		<p class="sfm">本服务由闪风猫提供</p>
	</div>
	<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
	<script src="http://code.jquery.com/jquery-3.2.1.min.js"></script>
	<script src="__JS__/vue.min.js"></script>
	<script src="__JS__/common.min.js"></script>
	<script>
		// 1.变量名称使用下划线法（$my_money）
		// 2.自定义函数使用下划线法 function generate_orderno(){}
		var app = new Vue({
			el: "#app",
			data: {
				type: 1,
				sendPrice: 0,
				sendNum: 0,   //发出红包个数
				getPrice: 0,
				getNum: 0,	 //收到红包个数
				mygive: '',  //发出的红包
				receive: '',  //收到的红包
				userInfo: ''   //用户信息			
			},
			computed: {
				 
			},
			mounted: function() {
				var that = this;				
				var url = location.href;
				$.ajax({
					url: '{:U('setting/wxJsSDK')}',
					type: 'post',
					data: {
						url: url,
						code: 1
					},
					success: function(data) {
						if (data.code != 200) {
							alert(data.msg);
							return false;
						}
						that.wxdata = data.data;
						wx.config({
						    debug: false, 
						    appId: that.wxdata.appId, 
						    timestamp: that.wxdata.timestamp, 
						    nonceStr: that.wxdata.nonceStr, 
						    signature: that.wxdata.signature,
						    jsApiList: [
						    	"onMenuShareTimeline",   //分享到朋友圈
								"onMenuShareAppMessage",  //分享给朋友
						    ] 
						});

						wx.ready(function(){
							// 获取用户信息
							$.ajax({
								url: '{:U('user/info')}',
								type: 'post',
								success: function(data) {
									if (data.code != 200) {
										alert(data.msg);
										return false;
									}
									that.userInfo = data.data;
									//获取我发出的红包数据
									$.ajax({
										type: 'post',
										url: '{:U('red/sendLog')}',
										success: function(data) {
											that.mygive = data.data.reds;
											that.sendNum = data.data.count;
											that.sendPrice = data.data.money;
										},
										error: function() {
											
										}
									})
									//获取我收到的红包数据
									$.ajax({
										type: 'post',
										url: '{:U('red/receiveLog')}',
										success: function(data) {
											that.receive = data.data.reds;
											that.getNum = data.data.count;
											that.getPrice = data.data.money;
										},
										error: function() {
											
										}
									})
								},
								error: function() {

								}
							})
							var url2 = url.split('record').join('send');
							wx.onMenuShareAppMessage({
							    title: '口令红包等你来抢', 
							    desc: '口令红包 说对算你赢', 
							    link: url2, 
							    imgUrl: 'http://sfmhb.shanfengmao.com/logo.png', 
							    type: '', 
							    dataUrl: '', 
							    success: function () { 
							        
							    },
							    cancel: function () { 
							        // 用户取消分享后执行的回调函数
							    }
							});
							wx.onMenuShareTimeline({
							    title: '口令红包等你来抢', 
							    link: url2, 
							    imgUrl: 'http://sfmhb.shanfengmao.com/logo.png', 
							    success: function () { 
							        
							    },
							    cancel: function () { 
							        // 用户取消分享后执行的回调函数
							    }
							});
						});
						wx.error(function(res){
						    alert("调用失败")
						});
					},
					error: function() {

					}
				})				
			},
			methods: {
				goto: function(id) {
					location.href = '{:U('red/find')}' + '?id=' + id;
				}
			},
			filters:{
			   toFixed:function (totalMoney) {
			        return Number(totalMoney).toFixed(2);
			    },
			    time:function (time) {
			        var time2 = time.substr(5);
			        var time2 = time2.split('-').join('月').split(' ').join('日 ');
			        return time2;
			    },
			}
		})
	</script>
</body>
</html>